package entity;

import Exception.InvalidWorkHoursException;


public class RegularEmployee extends Employee {
    private double hourlyRate;
    private double workHours;

    public RegularEmployee(String name, String empId, double hourlyRate, double workHours) {
        super(name, empId);
        this.hourlyRate = hourlyRate;
        this.workHours = workHours;
    }

    @Override
    public double calculateSalary() throws InvalidWorkHoursException {
        if (workHours < 0 || workHours > 168) {
            throw new InvalidWorkHoursException("工作时长异常：" + workHours + "小时（有效范围：0-168小时）");
        }
        return hourlyRate * workHours;
    }

    @Override
    public String generatePaySlip() {
        try {
            return "===== 工资条 =====\n" +
                    "员工姓名：" + getName() + "\n" +
                    "员工工号：" + getEmpId() + "\n" +
                    "员工类型：普通员工\n" +
                    "时薪标准：" + hourlyRate + "元/小时\n" +
                    "工作时长：" + workHours + "小时\n" +
                    "应发薪资：" + calculateSalary() + "元\n" +
                    "==================";
        } catch (InvalidWorkHoursException e) {
            return "工资条生成失败：" + e.getMessage();
        }
    }
}
